package net.alan.modules.listener;

import net.alan.modules.cache.WebContextUtil;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.Collection;

/**
 * Author 李岩飞
 * Email eliyanfei@126.com
 * 2017/12/2
 */
@WebListener
public class SessionListener implements HttpSessionListener {

    public void sessionCreated(HttpSessionEvent arg0) {
    }


    public void sessionDestroyed(HttpSessionEvent arg0) {
        HttpSession session = arg0.getSession();
        Collection<String> list = WebContextUtil.onlineMap.keySet();
        for (String key : list) {
            if (session.getId().equals(WebContextUtil.onlineMap.get(key))) {
                WebContextUtil.onlineMap.remove(key);
                break;
            }
        }
    }
}
